/**
 * Created by wangzilong on 2017/4/12.
 */
import React, { Component } from 'react';
import {
    AppRegistry,
    StyleSheet,
    Image
} from 'react-native';
export default class ImageWrapper extends Component {
    constructor(props){
        super(props);
        this.state = {
            icon: props.icon,
        };
    }

    componentWillReceiveProps(newProps){
        this.setState({
            icon: newProps.icon || '',
        });
    }

    _getSource(){
        return (iconMap[this.state.icon] || this.state.icon);
    }

    render() {
        var width = this.props.width || 20;
        var height = this.props.height || 20;
        var source = this._getSource();
        if(!source){
            return null;
        }
        return (
            <Image resizeMode={this.props.resizeMode||"stretch"} source={source} style={[styles.image, {width: width, height: height}, this.props.style]} />
        );
    }
}

const styles = StyleSheet.create({
    image: {
        width: 20,
        height: 20,
    },
});

const iconMap = {
    'touxiang':require('../img/icon/touxiang.png'),
    'saomiao':require('../img/icon/saomiao.png'),
    'black':require('../img/black.png'),
    'pink':require('../img/pink.png'),
    'white':require('../img/white.png'),
    'yellow':require('../img/yellow.png'),
    'dogTag':require('../img/dogTag.png'),
    'logo':require('../img/logo.png'),
    'yy':require('../img/icon/yuyue.png'),
    'qun':require('../img/icon/qun.png'),
    'hyzl':require('../img/icon/huiyuanziliao.png'),
    'wyjh':require('../img/icon/jinhuoche.png'),
    'spgl':require('../img/icon/shangpinguanli.png'),
    'fbhd':require('../img/icon/fabuhuodong.png'),
    'htfb':require('../img/icon/chongwu.png'),
    'dbgz':require('../img/icon/gouzheng.png'),
    'jkgl':require('../img/icon/jiankong.png'),
    'home':require('../img/icon/home.png'),
    'message':require('../img/icon/xiaoxi.png'),
    'Info':require('../img/icon/rizhi.png'),
    'mine':require('../img/icon/wode.png'),
    'phone':require('../img/icon/phone.png'),
    'password':require('../img/icon/password.png'),
    'eye':require('../img/icon/eye.png'),
    'button':require('../img/icon/button.png'),
    'left':require('../img/icon/left.png'),
    'shop':require('../img/icon/shop.png'),
    'circle':require('../img/icon/circle.png'),
    'selected':require('../img/icon/selected.png'),
    'addImg':require('../img/icon/addImg.png'),
    'right':require('../img/icon/right.png'),
    'explain':require('../img/icon/explain.png'),
    'setting':require('../img/icon/setting.png'),
    'account':require('../img/icon/account.png'),
    'bankCard':require('../img/icon/bankCard.png'),
    'cash':require('../img/icon/cash.png'),
    'review':require('../img/icon/review.png'),
    'voice':require('../img/icon/voice.png'),
    'closeBtn':require('../img/icon/closeBtn.png'),
    'openBtn':require('../img/icon/openBtn.png'),
    'add':require('../img/icon/add.png'),
    'eyeBlue':require('../img/icon/eyeBlue.png'),
    'person':require('../img/icon/person.png'),
    'up':require('../img/icon/up.png'),
    'down':require('../img/icon/down.png'),
    'iconDelete':require('../img/icon/iconDelete.png'),
    'icon_code':require('../img/icon/icon_code.png'),
    'tag':require('../img/icon/tag.png'),
    'card':require('../img/icon/card.png'),
    'club':require('../img/icon/club.png'),
    'discrib':require('../img/icon/discrib.png'),
    'address':require('../img/icon/address.png'),
    'search':require('../img/icon/search.png'),
    'notice':require('../img/icon/notice.png'),
    'v':require('../img/icon/v.png'),
    'addManager':require('../img/icon/addManager.png'),
    'stop':require('../img/icon/stop.png'),
    'point':require('../img/icon/point.png'),
    'iconClub':require('../img/icon/iconClub.png'),
    'qq':require('../img/icon/qq.png'),
    'wx':require('../img/icon/wx.png'),
};